<?php

/**
 * This is the model class for table "player".
 *
 * The followings are the available columns in table 'player':
 * @property string $ID
 * @property string $PLAYER
 * @property integer $HANDICAP
 * @property string $COMPANY_ID
 *
 * The followings are the available model relations:
 * @property Member[] $members
 * @property Company $cOMPANY
 * @property TeeTime[] $teeTimes
 */
class Player extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Player the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'player';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('ID', 'required'),
			array('HANDICAP', 'numerical', 'integerOnly'=>true),
			array('ID, COMPANY_ID', 'length', 'max'=>5),
			array('PLAYER', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('ID, PLAYER, HANDICAP, COMPANY_ID', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'members' => array(self::HAS_MANY, 'Member', 'PLAYER_ID'),
			'cOMPANY' => array(self::BELONGS_TO, 'Company', 'COMPANY_ID'),
			'teeTimes' => array(self::HAS_MANY, 'TeeTime', 'PLAYER_ID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'ID' => 'ID',
			'PLAYER' => 'Player',
			'HANDICAP' => 'Handicap',
			'COMPANY_ID' => 'Company',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('ID',$this->ID,true);
		$criteria->compare('PLAYER',$this->PLAYER,true);
		$criteria->compare('HANDICAP',$this->HANDICAP);
		$criteria->compare('COMPANY_ID',$this->COMPANY_ID,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}